package com.example.capsule_netty.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @Author: zhuzhiming
 * @Date: 2022/5/9 12:22
 */
public class MessageBeanDecoder extends ReplayingDecoder<MessageBeanProtocol> {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        int len = byteBuf.readInt();
        byte[] content = new byte[len];
        byteBuf.readBytes(content);
        MessageBeanProtocol messageBeanProtocol = new MessageBeanProtocol();
        messageBeanProtocol.setLen(len);
        messageBeanProtocol.setContent(content);
        list.add(messageBeanProtocol);
    }
}
